// pages/main/myshangpin/list/list.js
import user from "../../../../class/Utils/User"
import http from "../../../../class/Utils/Http"
import tips from "../../../../class/Utils/Tips"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    param:{'uid':wx.getStorageSync('user').userid,'p':1,'state':1}
  },
  onLoad: function (options) {
    
  },
  onShow: function () {
    tips.loading("加载中")
    var that =this
    var param = that.data.param
    http.req("/Api/product_list", param, function (res) {
      //console.log(res)
      for (var i = 0; i < res.pw_rec_list.length; i++) {
        res.pw_rec_list[i].pic = []
        if(res.pw_rec_list[i].pic1 && !/http/.test(res.pw_rec_list[i].pic1)){
          res.pw_rec_list[i].pic.push("http://img.i.album.toocle.com/0-0-0-1/"+res.pw_rec_list[i].pic1)
        }
        if(res.pw_rec_list[i].pic2 && !/http/.test(res.pw_rec_list[i].pic2)){
          res.pw_rec_list[i].pic.push("http://img.i.album.toocle.com/0-0-0-1/"+res.pw_rec_list[i].pic2)
        }
        if(res.pw_rec_list[i].pic3 && !/http/.test(res.pw_rec_list[i].pic3)){
          res.pw_rec_list[i].pic.push("http://img.i.album.toocle.com/0-0-0-1/"+res.pw_rec_list[i].pic3)
        }
      }
      that.setData({
          list: res.pw_rec_list
      })
      tips.loaded()
      console.log(that.data.list)
    })
  },
  onReachBottom: function () {
    //tips.loading("加载中")
    var that = this
    var param = that.data.param
    param.p++
    that.setData({
        param: param
    })
    var list = that.data.list
    http.req("/Api/product_list", param, function (res) {
      for (var i = 0; i < res.pw_rec_list.length; i++) {
        res.pw_rec_list[i].pic = []
        if(res.pw_rec_list[i].pic1 && !/http/.test(res.pw_rec_list[i].pic1)){
          res.pw_rec_list[i].pic.push("http://img.i.album.toocle.com/0-0-0-1/"+res.pw_rec_list[i].pic1)
        }
        if(res.pw_rec_list[i].pic2 && !/http/.test(res.pw_rec_list[i].pic2)){
          res.pw_rec_list[i].pic.push("http://img.i.album.toocle.com/0-0-0-1/"+res.pw_rec_list[i].pic2)
        }
        if(res.pw_rec_list[i].pic3 && !/http/.test(res.pw_rec_list[i].pic3)){
          res.pw_rec_list[i].pic.push("http://img.i.album.toocle.com/0-0-0-1/"+res.pw_rec_list[i].pic3)
        }
        list.push(res.pw_rec_list[i])
      }
      that.setData({
          list: list
      })
      //tips.loaded()
    })

    },
  //选择分类
  selectfenlei: function (e) {
    tips.loading("加载中")
    var that = this
    var param = that.data.param
    param.state = e.currentTarget.dataset.ctype
    param.p = 1
    that.setData({
       param: param
    })
    wx.pageScrollTo({
        scrollTop: 0,
        duration: 0
    })
    http.req("/Api/product_list", param, function (res) {
      //console.log(res)
      for (var i = 0; i < res.pw_rec_list.length; i++) {
        res.pw_rec_list[i].pic = []
        if(res.pw_rec_list[i].pic1 && !/http/.test(res.pw_rec_list[i].pic1)){
          res.pw_rec_list[i].pic.push("http://img.i.album.toocle.com/0-0-0-1/"+res.pw_rec_list[i].pic1)
        }
        if(res.pw_rec_list[i].pic2 && !/http/.test(res.pw_rec_list[i].pic2)){
          res.pw_rec_list[i].pic.push("http://img.i.album.toocle.com/0-0-0-1/"+res.pw_rec_list[i].pic2)
        }
        if(res.pw_rec_list[i].pic3 && !/http/.test(res.pw_rec_list[i].pic3)){
          res.pw_rec_list[i].pic.push("http://img.i.album.toocle.com/0-0-0-1/"+res.pw_rec_list[i].pic3)
        }
      }
      that.setData({
          list: res.pw_rec_list
      })
      tips.loaded()
    })
  },
  //去添加
  gotoadd:function(){
    var that = this
    tips.goto('/pages/main/myshangpin/add/add')
  },
  //去修改
  gotomod:function(e){
    tips.goto('/pages/main/myshangpin/add/add?id=' + e.currentTarget.dataset.id)
  },
})